package hczc.longcai.com.hccrowdfunding.home.fourth_mine.fragments;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.application.BaseApplication;
import hczc.longcai.com.hccrowdfunding.home.fourth_mine.beans.Voucher;
import hczc.longcai.com.hccrowdfunding.home.fourth_mine.utils.MineDataClickListener;

/**
 * A simple {@link Fragment} subclass.
 */
public class Mine_Data_Normal_Fragment extends Fragment {

    public static final int STATE_NICKNAME = 0;
    public static final int STATE_CHANGEPHONENUMBER = 1;
    public static final int STATE_ADDRESS = 2;
    public static final int STATE_APPLY = 3;
    public static final int STATE_CHANGEPASSWD = 4;

    private int state = 0;

    private MineDataClickListener listener;

    private static final String TAG = "Mine_Data_normal_Fragment";
    private LinearLayout parentLayout;
    private static String[] titles = {"昵称","更换手机号","收货地址","申请认证","修改密码"};
    private static int[] tabs = {R.mipmap.nc,R.mipmap.ghsjh,R.mipmap.shdz,
                                    R.mipmap.sqrz,R.mipmap.xgmm};

    public Mine_Data_Normal_Fragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mine__data__normal_, container, false);
        BaseApplication.scaleScreenHelper.loadView(((ViewGroup) view));
        parentLayout = ((LinearLayout) view);
        parentLayout.setOrientation(LinearLayout.VERTICAL);
        initViews(inflater,parentLayout);


        return view;
    }

    private void initViews(LayoutInflater inflater,LinearLayout parentLayout) {
        for(int i = 0;i < 6;i++){
            if(i != 3) {
                View v = inflater.inflate(R.layout.mine_data_normal, null, false);
                BaseApplication.scaleScreenHelper.loadView(((ViewGroup) v));
                ImageView tab = (ImageView) v.findViewById(R.id.mine_data_normal_tab);
                TextView text = (TextView) v.findViewById(R.id.mine_data_normal_text);
                TextView state = (TextView) v.findViewById(R.id.mine_data_normal_state);
                ImageView jinru = (ImageView) v.findViewById(R.id.mine_data_normal_jinru);
                setElement(v,i,tab,text,state,jinru);
                parentLayout.addView(v);
            }
            else {
                View fengexian = inflater.inflate(R.layout.fengexian, null, false);
                BaseApplication.scaleScreenHelper.loadView(((ViewGroup) fengexian));
                parentLayout.addView(fengexian);
            }
        }
    }

    private void setElement(View v,int i, ImageView tab, TextView text, TextView state, ImageView jinru) {
        switch (i){
            case 0:
                tab.setImageResource(tabs[0]);
                text.setText(titles[0]);
                state.setText("Angel");
                jinru.setVisibility(View.GONE);
                listener = new MineDataClickListener(getActivity(),STATE_NICKNAME);
                v.setOnClickListener(listener);
                break;
            case 1:
                tab.setImageResource(tabs[1]);
                text.setText(titles[1]);
                state.setText("13946446701");
                listener = new MineDataClickListener(getActivity(),STATE_CHANGEPHONENUMBER);
                v.setOnClickListener(listener);
                break;

            case 2:
                tab.setImageResource(tabs[2]);
                text.setText(titles[2]);
                state.setVisibility(View.GONE);
                listener = new MineDataClickListener(getActivity(),STATE_ADDRESS);
                v.setOnClickListener(listener);
                break;

            case 4:
                tab.setImageResource(tabs[3]);
                text.setText(titles[3]);
                state.setVisibility(View.GONE);
                listener = new MineDataClickListener(getActivity(),STATE_APPLY);
                v.setOnClickListener(listener);
                break;
            case 5:
                tab.setImageResource(tabs[4]);
                text.setText(titles[4]);
                state.setVisibility(View.GONE);
                listener = new MineDataClickListener(getActivity(),STATE_CHANGEPASSWD);
                v.setOnClickListener(listener);
                break;

        }
    }


}
